package zuoye08;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class zuoye04 {
    public static void main(String[] args) throws IOException {
        BufferedReader count=new BufferedReader(new FileReader("count.txt"));
        BufferedReader count1=new BufferedReader(new FileReader("count1"));
        BufferedReader count2=new BufferedReader(new FileReader("count2.txt"));
        int num=Integer.parseInt(count.readLine());
        int num1=Integer.parseInt(count1.readLine());
        int num2=Integer.parseInt(count2.readLine());
        FileReader fr=new FileReader("names.txt");
        BufferedReader br=new BufferedReader(fr);
        String read=br.readLine();
        ArrayList<String> arr=new ArrayList<>();
        while (read!=null) {
            arr.add(read);
            read=br.readLine();
        }
        Collections.sort(arr);
        //System.out.println(arr);
        ArrayList<String> boy=new ArrayList<>();
        ArrayList<String> girl=new ArrayList<>();
        for(String a:arr)
        {
          if(a.contains("男"))
          {StringBuilder c=new StringBuilder();
              c.append(a.split("-")[0]).append("-").append(a.split("-")[1]);
              boy.add(c.toString());
          }
          if(a.contains("女"))
          {
              StringBuilder c=new StringBuilder();
              c.append(a.split("-")[0]).append("-").append(a.split("-")[1]);
              girl.add(c.toString());
          }
        }

        Random rd=new Random();
        int d=rd.nextInt(10);
        String n="";
        if(d>=0&&d<=6)
        {
            if(!boy.isEmpty()){
                int c=rd.nextInt(boy.size()-1);
         num1++;
         n= boy.get(c);
            }
        }
        else if(d>=7&&d<=9)
        { if(!girl.isEmpty()){
            int c=rd.nextInt(girl.size()-1);
            num2++;
            n= girl.get(c);}
        }
        System.out.println("第"+num+"次点名"+n+num1+":"+num2);
        FileWriter fw1=new FileWriter("count.txt");
        FileWriter fw2=new FileWriter("count1");
        FileWriter fw3=new FileWriter("count2.txt");
        if(num<10) {
            fw1.write(Integer.toString(num + 1));
            fw2.write(Integer.toString(num1));
            fw3.write(Integer.toString(num2));
        }
        if(num==10) {
            num = 0;
            num1 = 0;
            num2 = 0;
            fw1.write(Integer.toString(num + 1));
            fw2.write(Integer.toString(num1));
            fw3.write(Integer.toString(num2));
        }
        fr.close();
        fw1.close();
        count.close();
        count1.close();
        count2.close();
        fw2.close();
        fw3.close();

    }
    }
